package com.tuan.common.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;




@Controller
public class CommonAction {
	private static final org.apache.log4j.Logger log = org.apache.log4j.Logger
			.getLogger(CommonAction.class);
	private static final String RETURN_VM = "login";

    private static final String SUCCESS_VM = "index.htm";
    
	@RequestMapping("index.htm")
	public String index() {
		return "index";
	}
	
	@RequestMapping(value="account/login.htm", method = RequestMethod.GET)
	public String login(ModelMap map, HttpServletRequest request,
			@ModelAttribute("loginForm") UserForm loginForm){
        
        return "account/login";
	}
	
	@RequestMapping(value="account/login.htm", method = RequestMethod.POST)
	public String doLogin(ModelMap map, HttpServletRequest request,
            HttpSession session,
            @ModelAttribute("loginForm") UserForm loginForm,
            BindingResult bindingResult,
            @RequestParam("goto") String paramGoto){
		
		return "account/logout";
	}
	
	
	@RequestMapping(value="account/signup.htm", method = RequestMethod.GET)
	public String logon(ModelMap map, HttpServletRequest request,
			@ModelAttribute("logonForm") UserForm logonForm,
			BindingResult bindingRequest) {
		return "account/signup";
	}
	
	@RequestMapping(value="account/signup.htm", method = RequestMethod.POST)
	public String doLogon(ModelMap map, HttpSession session,
            HttpServletRequest request, @ModelAttribute("logonForm")
            UserForm logonForm, BindingResult bindingRequest){
		log.debug(logonForm.getName());
		
		return "account/signup";
	}
	
	
	@RequestMapping("logout.htm")
	public String logout(){
		return "account/logout";
	}
}
